package com.cube.dp.base.utils;

import org.springframework.lang.Nullable;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;

/**
 * @author cube.li
 * @date 2021/12/23 14:47
 * <p>
 * http响应工具类
 */
public class ResponseUtils {

    @Nullable
    public static HttpServletResponse currentResponse() {
        ServletRequestAttributes requestAttributes = currentServletRequestAttributes();
        if (requestAttributes == null) {
            return null;
        }
        return requestAttributes.getResponse();
    }

    @Nullable
    public static ServletRequestAttributes currentServletRequestAttributes() {
        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }
}
